package com.moxi.mogublog.commons.feign;

import com.moxi.mogublog.commons.feign.impl.RedisFeignClientImpl;
import com.moxi.mogublog.config.feign.FeignConfiguration;
import com.moxi.mougblog.base.result.ResultVO;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Set;

/**
 * Redis 远程调用 [Feign]
 * <p/>
 * FeignClient 这里的服务名不区分大小写
 *
 * @author LiShuai
 * @date 2020/5/29 13:49
 */
@FeignClient(name = "common-redis", fallback = RedisFeignClientImpl.class, configuration = FeignConfiguration.class)
public interface RedisFeignClient {

    /**
     * 获取Redis详细信息
     *
     * @return
     */
    @GetMapping(value = "/redis/info")
    ResultVO<List> getRedisInfo();

    /**
     * 字符串（String）-设置指定 key 的值
     *
     * @param key   键
     * @param value 键
     * @return
     */
    @PostMapping(value = "/redis/set")
    ResultVO<String> set(
            @RequestParam(name = "key", required = true) String key,
            @RequestParam(name = "value", required = true) Object value);

    /**
     * 字符串（String）-设置指定 key 的值
     *
     * @param key           键
     * @param value         键
     * @param expireSeconds 过期时间
     * @return
     */
    @PostMapping(value = "/redis/setEx")
    ResultVO<String> setEx(
            @RequestParam(name = "key", required = true) String key,
            @RequestParam(name = "value", required = true) Object value,
            @RequestParam(name = "expireSeconds", required = true) int expireSeconds);

    /**
     * 字符串（String）-获取指定 key 的值
     *
     * @param key
     * @return
     */
    @GetMapping(value = "/redis/string/get")
    ResultVO<String> get(@RequestParam(value = "key", required = true) String key);

    /**
     * 获取指定前缀的key
     *
     * @param keyPrefix
     * @return
     */
    @GetMapping(value = "/keys")
    ResultVO keys(@RequestParam(value = "keyPrefix", required = true) String keyPrefix);

    /**
     * 字符串（String）-根据指定的key删除
     *
     * @param key
     * @return
     */
    @DeleteMapping(value = "/del")
    ResultVO delete(@RequestParam(value = "key", required = true) String key);

    /**
     * 字符串（String）-根据指定的key删除
     *
     * @param keys
     * @return
     */
    @DeleteMapping(value = "/dels")
    ResultVO delete(@RequestParam(value = "keys", required = true) Set<String> keys);

}
